import chinaAreaData from 'china-area-data'

/**
 * @param {Array} value
 * @returns {Boolean}
 * @example see @/views/permission/directive.vue
 */
export default function areaTreeData() {
  const tree = []
  const provinces = chinaAreaData['86']
  Object.keys(provinces).forEach(key => {
    const province = {
      id: key,
      label: provinces[key],
      children: getChildren(key)
    }
    tree.push(province)
  })
  return tree
}

function getChildren(pid) {
  const children = []
  const childrens = chinaAreaData[pid]
  if (childrens) {
    Object.keys(childrens).forEach(key => {
      const province = {
        id: key,
        label: childrens[key],
        children: getChildren(key)
      }
      children.push(province)
    })
  }
  return children
}
